Part Number Hot Search : 
FMM5820X XM15E06 MF0603X5 CY7C42 10K250A TC74LCX5 BUX78SMD LT1012
Product Description
Full Text Search
 

To Download DS41356B Datasheet File

  If you can't view the Datasheet, Please click here to try to view without PDF Reader .  
 
 


  Datasheet File OCR Text:
  ? 2009 microchip technology inc. DS41356B low pin count usb development kit user?s guide
DS41356B-page ii ? 2009 microchip technology inc. information contained in this publication regarding device applications and the like is provided only for your convenience and may be superseded by updates. it is your responsibility to ensure that your application meets with your specifications. microchip makes no representations or warranties of any kind whether express or implied, written or oral, statutory or otherwise, related to the information, including but not limited to its condition, quality, performance, merchantability or fitness for purpose . microchip disclaims all liability arising from this information and its use. use of microchip devices in life support and/or safety applications is entirely at the buyer?s risk, and the buyer agrees to defend, indemnify and hold harmless microchip from any and all damages, claims, suits, or expenses resulting from such use. no licenses are conveyed, implicitly or otherwise, under any microchip intellectual property rights. trademarks the microchip name and logo, the microchip logo, accuron, dspic, k ee l oq , k ee l oq logo, mplab, pic, picmicro, picstart, rfpic, smartshunt and uni/o are registered trademarks of microchip tec hnology incorporated in the u.s.a. and other countries. filterlab, linear active thermistor, mxdev, mxlab, seeval, smartsensor and the embedded control solutions company are registered trademarks of microchip technology incorporated in the u.s.a. analog-for-the-digital age, appl ication maestro, codeguard, dspicdem, dspicdem.net, dspicworks, dsspeak, ecan, economonitor, fansense, in-circuit serial programming, icsp, icepic, mindi, miwi, mpasm, mplab certified logo, mplib, mplink, mtouch, pickit, picdem, picdem.net, pictail, pic 32 logo, powercal, powerinfo, powermate, powertool, real ice, rflab, select mode, total endurance, wiperlock and zena are trademarks of microchip technology incorporated in the u.s.a. and other countries. sqtp is a service mark of microchip technology incorporated in the u.s.a. all other trademarks mentioned herein are property of their respective companies. ? 2009, microchip technology incorporated, printed in the u.s.a., all rights reserved. printed on recycled paper. note the following details of the code protection feature on microchip devices: ? microchip products meet the specification cont ained in their particular microchip data sheet. ? microchip believes that its family of products is one of the mo st secure families of its kind on the market today, when used i n the intended manner and under normal conditions. ? there are dishonest and possibly illegal methods used to breach the code protection feature. all of these methods, to our knowledge, require using the microchip produc ts in a manner outside the operating specifications contained in microchip?s data sheets. most likely, the person doing so is engaged in theft of intellectual property. ? microchip is willing to work with the customer who is concerned about the integrity of their code. ? neither microchip nor any other semiconductor manufacturer c an guarantee the security of their code. code protection does not mean that we are guaranteeing the product as ?unbreakable.? code protection is constantly evolving. we at microchip are co mmitted to continuously improvi ng the code protection features of our products. attempts to break microchip?s c ode protection feature may be a violation of the digital millennium copyright act. if such acts allow unauthorized access to your software or other copyrighted work, you may have a right to sue for relief under that act. microchip received iso/ts-16949:2002 certification for its worldwide headquarters, design and wafer fabrication facilities in chandler and tempe, arizona; gresham, oregon and design centers in california and india. the company?s quality system processes and procedures are for its pic ? mcus and dspic ? dscs, k ee l oq ? code hopping devices, serial eeproms, microperipherals, nonvolatile memory and analog products. in addition, microchip?s quality system for the design and manufacture of development systems is iso 9001:2000 certified.
low pin count usb development kit user?s guide ? 2009 microchip technology inc. DS41356B-page iii table of contents preface ....................................................................................................................... .... 1 introduction ......................................................................................................... 1 document layout................................................................................................ 1 conventions used in this guide ......................................................................... 2 recommended reading ..................................................................................... 3 the microchip web site...................................................................................... 3 customer support............................................................................................... 4 document revision history ................................................................................ 4 chapter 1: overview introduction .......................................................................................................... 5 highlights ............................................................................................................. 5 low pin count usb development kit contents .................................................. 5 low pin count usb development board construction and layout .................... 6 pic18f14k50 icd debug header ...................................................................... 7 ?getting started with microchip?s low pin count usb solutions? self-directed course ...................................................................................................... 7 introduction .......................................................................................................... 9 prerequisites ....................................................................................................... 9 resources required to complete project labs .................................................. 9 chapter 2: getting started project labs project lab 1 (enumeration) ............................................................................. 10 2.4.1 purpose ......................................................................................... 10 2.4.2 procedure ...................................................................................... 10 testing the application .......................................................................... 17 project lab 2 (hid mouse) ................................................................................ 18 2.5.1 purpose ......................................................................................... 18 2.5.2 overview of the hid mouse firmware ........................................... 19 2.5.3 procedure ...................................................................................... 20 testing the application ........................................................................... 21 project lab 3 (hid keyboard) ........................................................................... 22 2.6.1 overview of the hid keyboard firmware ...................................... 22 2.6.2 procedure ...................................................................................... 24 testing the application ........................................................................... 27
low pin count usb develop ment kit user?s guide DS41356B-page iv ? 2009 microchip technology inc. project lab 4 (cdc ? serial emulator) ............................................................. 28 2.7.1 overview of the cdc ? serial emulator firmware ........................ 29 2.7.2 procedure ...................................................................................... 31 installing application drivers .................................................................. 37 establish communication ....................................................................... 40 testing the application ........................................................................... 42 worldwide sales and service .....................................................................................50
low pin count usb development kit user?s guide ? 2009 microchip technology inc. DS41356B-page 1 preface introduction this chapter contains general information that will be useful to know before using the low pin count usb development kit. items discussed in this chapter include: ? document layout ? conventions used in this guide ? recommended reading ? the microchip web site ? customer support ? document revision history document layout this document describes how to use the low pin count usb development kit as a development tool to emulate and debug firmware on a target board. the manual layout is as follows: ? chapter 1. ?overview? ? chapter 2. ?getting started project labs? ? appendix a. ?schematics? notice to customers all documentation becomes dated, and this manual is no exception. microchip tools and documentation are constantly evolving to meet customer needs, so some actual dialogs and/or tool descriptions may differ from those in this document. please refer to our web site (www.microchip.com) to obtain the latest documentation available. documents are identified with a ?ds? number. this number is located on the bottom of each page, in front of the page number. the numbering convention for the ds number is ?dsxxxxxa?, where ?xxxxx? is the document number and ?a? is the revision level of the document. for the most up-to-date information on development tools, see the mplab ? ide on-line help. select the help menu, and then topics to open a list of available on-line help files.
low pin count usb develop ment kit user?s guide DS41356B-page 2 ? 2009 microchip technology inc. conventions used in this guide this manual uses the following documentation conventions: documentation conventions description represents examples arial font: italic characters referenced books mplab ? ide user?s guide emphasized text ...is the only compiler... initial caps a window the output window a dialog the settings dialog a menu selection select enable programmer quotes a field name in a window or dialog ?save project before build? underlined, italic text with right angle bracket a menu path file>save bold characters a dialog button click ok a tab click the power tab n?rnnnn a number in verilog format, where n is the total number of digits, r is the radix and n is a digit. 4?b0010, 2?hf1 text in angle brackets < > a key on the keyboard press , courier new font: plain courier new sample source code #define start filenames autoexec.bat file paths c:\mcc18\h keywords _asm, _endasm, static command-line options -opa+, -opa- bit values 0, 1 constants 0xff, ?a? italic courier new a variable argument file .o , where file can be any valid filename square brackets [ ] optional arguments mcc18 [options] file [options] curly brackets and pipe character: { | } choice of mutually exclusive arguments; an or selection errorlevel {0|1} ellipses... replaces repeated text var_name [, var_name...] represents code supplied by user void main (void) { ... }
preface ? 2009 microchip technology inc. DS41356B-page 3 recommended reading this user?s guide describes how to use the low pin count usb development kit. other useful documents are listed below. the following microchip documents are available and recommended as supplemental reference resources. readme files for the latest information on using other tools, read the tool-specific readme files in the readmes subdirectory of the mplab ? ide installation directory. the readme files contain update information and known issues that may not be included in this user?s guide. design center microchip has a usb design center which can be found on www.microchip.com/usb . the following microchip application notes are available and recommended as supplemental reference resources. the microchip web site microchip provides online support via our web site at www.microchip.com. this web site is used as a means to make files and information easily available to customers. accessible by using your favorite internet browser, the web site contains the following information: ? product support ? data sheets and errata, application notes and sample programs, design resources, user?s guides and hardware support documents, latest software releases and archived software ? general technical support ? frequently asked questions (faqs), technical support requests, online discussion groups, microchip consultant program member listing ? business of microchip ? product selector and ordering guides, latest microchip press releases, listing of seminars and events, listings of microchip sales offices, distributors and factory representatives
low pin count usb develop ment kit user?s guide DS41356B-page 4 ? 2009 microchip technology inc. customer support users of microchip products can receive assistance through several channels: ? distributor or representative ? local sales office ? field application engineer (fae) ? technical support customers should contact their distributor, representative or field application engineer (fae) for support. local sales offices are also available to help customers. a listing of sales offices and locations is included in the back of this document. technical support is available through the web site at: http://support.microchip.com document revision history revision a (september 2008) ? initial release of this document. revision b (february 2009) ? corrected document errors
low pin count usb development kit user?s guide ? 2009 microchip technology inc. DS41356B-page 5 chapter 1. overview 1.1 introduction the low pin count usb development kit provides an easy, low cost way to evaluate the functionality of microchip?s pic18f14k50 and pic18f13k50 20-pin usb micro- controllers. the all-inclusive kit contains the hardware, software, and code examples necessary to bring your next usb design from concept to first prototype. created with the usb novice in mind, the kit includes ?getting started with microchip?s low pin count usb solutions? , a self-directed course and lab material designed to ease the learning curve associated with adding usb connectivity to embedded systems. 1.2 highlights this chapter discusses: ? low pin count usb development kit contents ? low pin count usb development board construction and layout 1.3 low pin count usb development kit contents the low pin count usb development kit contains the following: ? (1) fully populated low pin count usb development board ? (1) unpopulated spare development board ? (1) pic18f14k50 icd populated expansion header ? (1) cd containing the user guide, course materials and product documentation. ? (1) pickit? 2 debugger/programmer with cable. figure 1-1: low pin coun t usb development kit
low pin count usb develop ment kit user?s guide DS41356B-page 6 ? 2009 microchip technology inc. 1.4 low pin count usb deve lopment board construction and layout the low pin count usb development board and populated components are shown in figure 1-2. figure 1-2: low pin coun t usb development board 1. usb mini-b connector 2. j9 regulated 5v connection header 3. j14 connects either v bus (provided by usb) or j9 regulated 5v to pic18f14k50 v dd supply 4. pickit? 2 debugger/programmer connection header 5. leds connected to portc (rc0, rc1, rc2, rc3) 6. pickit? serial analyzer connection header 7. max3232 rs-232 line driver/receiver 8. rs-232 connector 9. area provided for user pid/vid information 10. potentiometer 11. j12 connects/disconnects v usb on pic18f14k50 12. push button 13. 12 mhz crystal 14. pic18f14k50 mcu 15. prototyping area 16. pictail? daughter board expansion header 17. ssop expansion 1 4 3 10 2 5 6 7 8 9 11 12 13 14 15 16 17 note: j2-j5, j7, j8 are shunted on the bottom side of the board and thus the functions default connected even though no jumper is installed. cut the jumper to disable the circuitry attached to each pin.
? 2009 microchip technology inc. DS41356B-page 7 1.5 pic18f14k50 icd debug header the low pin count usb development kit includes a debug header populated with a pic18f14k50 icd mcu to enable for use with the pickit? 2 debugger/programmer. figure 1-3: pic18f14k50 popula ted mplab icd 2 debug header to use the debug header, simply remove the pic18f14k50 mounted in the mcu socket (u2) on the low pin count usb development board. using a pin header (not included), connect the debug header into the mcu socket and connect the pickit? 2 programmer/debugger to the provided connection header. 1.6 ?getting started with mi crochip?s low pin count usb solutions? self-directed course the low pin count usb development kit includes the self-directed course ?getting started with microchip?s low pin count usb solutions? . this course provides an introductory overview to the usb 2.0 protocol and implementation on the pic18f14k50 mcu. microchip?s usb device firmware framework is introduced as a resource providing a library of firmware code for usb operation that handles ?low-level? tasks and a number of reference projects. the user is guided through a number of ?hands-on? labs to reinforce covered concepts.
low pin count usb develop ment kit user?s guide DS41356B-page 8 ? 2009 microchip technology inc. notes:
low pin count usb development kit user?s guide ? 2009 microchip technology inc. DS41356B-page 9 2.1 introduction this section of the user?s guide will walk the user through a number of project labs that will ease the development of original usb design applications. labs are formatted so that the user is guided through each project?s source code to uncomment or copy and paste sections of code. this format was chosen to force the developer to explore sig- nificant sections of the framework and familiarize themselves with the overall structure of the source files presented. lab files can be located in the folder c:\lpcusbdk_labs\labx_files . each lab folder will contain both the source files for the labs and a folder containing the solutions with working code. four labs are presented: 1. project lab 1 (enumeration): this lab introduces the user to developing unique descriptors in their own applications that will be used by the host (pc) to enumerate and ultimately configure the pic18f14k50. 2. project lab 2 (hid mouse): this lab expands on concepts learned in project lab 1 using the descriptors defined. the user will walk through the development of application specific functions within the mouse.c firmware file. the end applica- tion will behave like a human interface device class (hid) mouse by moving the pointer on the pc screen. 3. project lab 3 (hid keyboard): in this lab the user is required to alter the descrip- tors to implement a hid keyboard-based application. the potentiometer on the low pin count usb development board is rotated to change the hid specifica- tion unicode value transmitted through the usb to the pc that will print charac- ters based on an adc conversion. 4. project lab 4 (cdc serial emulator): finally, the user will implement a communication protocol converter using the communication device class (cdc) driver. 2.2 prerequisites these labs assume that the user: 1. has completed the self-directed course ?getting started with microchip?s low pin count usb solutions? provided on the accompanying cd. 2. is familiar with the mplab ide and c18 compiler. 3. has some programming experience using the c language. 4. is familiar with microchip?s pic18f family of microcontrollers. 2.3 resources required to complete project labs in order to complete the project labs, the user should have: 1. the most current version of the mplab ide and c18 compiler installed on their pc. the mplab ide can be found at: http://www.microchip.com/stellent/idc- plg?idcservice=ss_get_page&nodeid=1406&ddoc- name=en019469&part=sw007002 chapter 2. getting started project labs
low pin count usb develop ment kit user?s guide DS41356B-page 10 ? 2009 microchip technology inc. 2. the c18 compiler can be found at: http://www.microchip.com/stellent/idcplg?idc- service=ss_get_page&nodeid=1406&ddocname=en010014 3. the most current version of the pickit 2 programmer software. 4. downloaded and installed the microchip full-speed usb firmware framework. available free at: http://www.microchip.com/stellent/idcplg?idcser- vice=ss_get_page&nodeid=2651¶m=en534494 5. a copy of the ? microchip usb device firmware framework user?s guide? (ds51679) 6. a copy of the pic18f13k50/14k50 data sheet (ds41350) 7. a copy of the usb revision 2.0 specification available for download from: http://www.usb.org/developers/docs/ this will prove useful as reference throughout the labs. 8. a copy of the universal serial bus (usb) hid usage tables available for download at: http://www.usb.org/developers/devclass_docs/hut1_12.pdf 9. downloaded the usb hid descriptor tool available free at: http://www.usb.org/developers/hidpage/dt2_4.zip 10. a copy of the universal serial bus class definitions for communications devices document available for download at: http://www.usb.org/developers/devclass_docs 11. unzipped the lpcusbdk_labs.zip file to the c: directory. 2.4 project lab 1 (enumeration) 2.4.1 purpose the purpose of this lab is intended to introduce the user to creating a project in the mplab ide using microchip?s full-speed usb firmware framework. though many application examples in the framework can be used to create original code, building the framework from scratch is a great way to get familiar to the overall functionality of this multitasking tool. the user will create a project, ensure that the ide is configured accordingly, and alter the usb_descriptor.c file to enable the enumeration of the pic18f14k50 as a hid mouse device. 2.4.2 procedure 2.4.2.1 building the framework 1. open the mplab ide by selecting start>programs>microchip>mplab ide vx.xx>mplab ide 2. once in the mplab ide, start the project wizard by selecting project>project wizard 3. select the pic18f14k50 as the device, select the mplab c18 c compiler as the language toolsuite, and create a new project folder in the following directory: c:\microchip solutions\project lab 1\project lab 1 note: in this and all subsequent project labs, the usb cable must be discon- nected from the usb mini-b connector on the low pin count usb devel- opment board when programming with the pickit 2 programmer.
? 2009 microchip technology inc. DS41356B-page 11 4. in the add existing files to your project window, navigate to c:\lpcusbdk_labs\lab1_files and copy the following files: a) enumeration.c b) usb_descriptors.c c) hardwareprofile.h d) usb_config.h to copy a file, click on the large letter a in front of the file path in the right pane of the window until a large letter c appears. this mode makes a copy of this file into the new project directory leaving the original file intact. (see figure 2-1) figure 2-1: this next section will add the files that will build the framework that takes care of the low level usb functions. this does not need to be done for every application. the included example projects could be easily converted to suit the needs of a custom application. however, in the interest of providing an intuitive introduction to the framework, this lab builds this application from scratch. 5. next, navigate to c:\microchip solutions\microchip\include and copy over the following files: a) compiler.h b) generictypedefs.h note: these files are the user files that will need to be changed to implement any application. note: these files are used by all the applications in the framework. therefore, changing these files will affect all applications. if any of these files are inadvertently altered, it is recommended that the framework be reinstalled.
low pin count usb develop ment kit user?s guide DS41356B-page 12 ? 2009 microchip technology inc. 6. navigate to c:\microchip solutions\microchip\include\usb and copy the following files: a) usb.h b) usb_ch9.h c) usb_common.h d) usb_device.h e) usb_function_hid.h (file defines components specific to the hid class) f) usb_hal.h g) usb_hal_pic18.h (file defines components specific to the pic18 architecture) 7. next, navigate to c:\microchip solutions\microchip\usb and copy the following file: a) usb_device.c 8. next, navigate to c:\microchip solutions\microchip\usb\hid device driver to copy the hid specific source file: a) usb_function_hid.c 9. finally, navigate to c:\mcc18\lkr and copy the 18f14k50.lkr linker file. 10. click next> finish to exit the project wizard. the project window should now resemble figure 2-2. figure 2-2: project window for lab 1 if the project window isn?t open in the mplab ide workspace, select view> project . next the mplab ide will need to be configured for the framework by directing the c18 compiler to the associated file locations. 11. in the mplab ide, select project>build options?>project . the build options dialog will appear (figure 2-3).
? 2009 microchip technology inc. DS41356B-page 13 12. click on the directories tab and select output directory and click new to add a new path. click on the button, navigate to c:\lpcusbdk_labs\lab1_files and create a new folder called output . highlight the folder and click ok . this will now be the folder where the output files are placed. 13. within the ? show directories for ? drop-down menu, select the ?include search path ? directory. ensure that the c:\mcc18\h directory path is listed. select new and navigate to c:\microchip solutions\microchip\include and click ok to add to the directory. repeat these steps to add the application folder c:\lpcusbdk_labs\lab1_files . 14. in the ?show directories for:? drop-down menu, select library search path . ensure that the c:\mcc18\lib is listed . next, select the linker-script path and ensure that the path points to c:\mcc18\lkr directory. figure 2-3: config uring for microchip usb firmware framework 15. click apply, followed by ok to apply these settings and close the build options window. at this point, framework has been built. defining project descriptors double click the enumeration.c source file in the project window to open. scroll down to the processio(). note it is empty. therefore, this application will do noth- ing. the intention of this lab is to introduce the user to properly configure the firmware so that the pic18f14k50 will enumerate as a hid mouse once connected to the host pc. therefore, the usb_descriptors.c file will need to be altered accordingly. as a
low pin count usb develop ment kit user?s guide DS41356B-page 14 ? 2009 microchip technology inc. reference, the usb revision 2.0 specification should be opened to section 9-5 ?descriptors? . this section details the various components required in each type of descriptor (device, configuration, interface etc.). this usb_descriptor.c file should be an exact replica of the source file of the same name found in the framework folder c:\microchip solutions\usb device - hid - mouse\hid - mouse ? firmware\usb_descriptor.c this file can be used as a reference during debugging. 16. in the mplab ide project window, select and open the usb_descriptors.c source file. note #include "./usb/usb_function_hid.h" at the top of the file. if a different class of device is being defined for a given application, the appropriate class header file will need to be included here. 17. scroll down to the device descriptor section and copy and paste the code in example 2-1 between the curly brackets in the section labeled: //add device descriptor code here example 2-1: device descriptor for lab 1 18. scroll down to the configuration, class specific and interface descriptor section. copy and paste the code in example 2-2 between the brackets between the curly brackets in the section labeled: //add configuration, class specific and //interface descriptor code here note: the user may wish to clean up the look of the code by spacing comment sections accordingly. tabs were ignored to ensure completeness for this document. 0x12, // size of this descriptor in bytes usb_descriptor_device, // device descriptor type 0x0110, // usb spec release number in bcd format 0x00, // class code 0x00, // subclass code 0x00, // protocol code usb_ep0_buff_size, // max packet size for ep0, see // usbcfg.h my_vid, // vendor id my_pid, // product id 0x0003, // device release number in bcd format 0x01, // manufacturer string index 0x02, // product string index 0x00, // device serial number string index 0x01 // number of possible configurations
? 2009 microchip technology inc. DS41356B-page 15 example 2-2: conf iguration, class specific and interface the user is encouraged to take some time and compare the code in the preceding code examples against the descriptor definitions in the usb revision 2.0 specification section 9-5 ?descriptors? . comments have been included to make the code intuitive and easier to reference with the usb specification. definition sources can be located by highlighting the definition name and selecting edit>find in files in the mplab ide. this will locate all instances of the definition within the project and list them in the output window. 0x09,//sizeof(usb_cfg_dsc), // size of this descriptor in bytes usb_descriptor_configuration, // configuration descriptor type desc_config_word(0x0022), // total length of data for this cfg 1, // number of interfaces in this cfg 1, // index value of this configuration 0, // configuration string index _default|_self, // attributes, see usbd.h 50, // max power consumption (2x ma) /* interface descriptor */ 0x09,//sizeof(usb_intf_dsc), // size of this descriptor // in bytes usb_descriptor_interface, // interface descriptor type 0, // interface number 0, // alternate setting number 1, // number of endpoints in this intf hid_intf, // class code boot_intf_subclass, // subclass code hid_protocol_mouse, // protocol code 0, // interface string index /* hid class-specific descriptor */ 0x09,//sizeof(usb_hid_dsc)+3, // size of this descriptor in bytes dsc_hid, // hid descriptor type desc_config_word(0x0111), // hid spec release number in bcd // format(1.11) 0x00, // country code (0x00 for not // supported) hid_num_of_dsc, // number of class descriptors, see // usbcfg.h dsc_rpt, // report descriptor type desc_config_word(50), // sizeof(hid_rpt01), // size of the report descriptor /* endpoint descriptor */ 0x07,/*sizeof(usb_ep_dsc)*/ usb_descriptor_endpoint, // endpoint descriptor hid_ep | _ep_in, // endpointaddress _int, // attributes desc_config_word(3), // size 0x01 // interval
low pin count usb develop ment kit user?s guide DS41356B-page 16 ? 2009 microchip technology inc. 19. scroll down to the string descriptor section. string descriptors can be used to describe a device for the user. at enumeration, the string descriptor will appear at the lower right hand section of the screen notifying the user of the intended purpose of the device. copy and paste the code between the curly brackets for both the manufacturer string descriptor and product string descriptor in example 2-3 and example 2-4 in the sections labeled: //add manufacturer string descriptor code here and //add product string descriptor code here example 2-3: manufacturer st ring descriptor for lab 1 example 2-4: product stri ng descriptor for lab 1 finally, the last descriptor to be added is the report descriptor. early in the development of the hid class specification, subclasses were intended to be used to identify different hid device categories. however, it became clear that due to the diverse variety of devices that could be imple- mented in this class, a more robust definition method was required. therefore, this class does not use subclasses to define most protocols. instead, a mecha- nism called the report descriptor identifies data protocol and the types of data provided for a device. it is here that such things as the number of buttons on a mouse, the unicode key value ranges for a keyboard, and other such characteristics are defined. the usb organization has provided a number of documents and tools specifically designed to implement the report descriptor that can be accessed at: http://www.usb.org/developers/hidpage/ the user is encouraged to download the hid usage tables that define a report descriptor for a given device. also, the usb organization has further developed a hid descriptor tool that will assist the developer in designing their own report descriptors. the tool also includes predefined descriptors for commonly used hid devices such as a mouse and keyboard. this document and tool can be found at the links listed in section 2.3 ?resources required to complete project labs? . 20. scroll down to the report descriptor section and copy and paste the code in example 2-5 between the curly brackets in the section labeled: //add report descriptor code here 'm','i','c','r','o','c','h','i','p', ' ','t','e','c','h','n','o','l','o','g','y', ' ','i','n','c','.' 'm','o','u','s','e', ' ','e','n','u','m','e','r','a','t','i','o','n ', ' ','d','e','m','o'
? 2009 microchip technology inc. DS41356B-page 17 example 2-5: report descriptor for lab 1 the descriptor definitions are now complete. 21. compile the project. there should be no errors. testing the application 22. configure the low pin count usb development board so that the j14 jumper is on the two right-most pins. this application will use power supplied by v bus off of the usb cable. 23. disconnect the j12 jumper. 24. connect the pickit 2 programmer to the pc usb port and then to the j6 connector on the low pin count usb development board. 25. open the pickit 2 programmer environment by selecting start>programs>micro- chip pickit 2 vx.xx . 26. the pickit 2 programmer software should recognize that the pickit 2 is connected and identify the pic18f14k50 device. 27. within the pickit 2 programmer software, navigate to the c:\lpcusbdk_labs\lab1_files\output folder and download the project lab 1.hex file to the pic18f14k50. 28. disconnect the pickit 2 programmer from j6 and plug the usb cable into the mini b connector, j1. once connected, the enumeration process should begin. the host pc should recognize the connection of a new device and display a notification at the right corner of the screen indicating the ?mouse enumeration demo? text placed in the product string earlier in this lab. 0x05, 0x01, /* usage page (generic desktop)*/ 0x09, 0x02, /* usage (mouse)*/ 0xa1, 0x01, /* collection (application)*/ 0x09, 0x01, /* usage (pointer)*/ 0xa1, 0x00, /* collection (physical)*/ 0x05, 0x09, /* usage page (buttons) */ 0x19, 0x01, /* usage minimum (01)*/ 0x29, 0x03, /* usage maximum (03)*/ 0x15, 0x00, /* logical minimum (0)*/ 0x25, 0x01, /* logical maximum (0)*/ 0x95, 0x03, /* report count (3)*/ 0x75, 0x01, /* report size (1)*/ 0x81, 0x02, /* input (data, variable, absolute)*/ 0x95, 0x01, /* report count (1)*/ 0x75, 0x05, /* report size (5)*/ 0x81, 0x01, /* input (constant) ;5 bit padding */ 0x05, 0x01, /* usage page (generic desktop)*/ 0x09, 0x30, /* usage (x)*/ 0x09, 0x31, /* usage (y)*/ 0x15, 0x81, /* logical minimum (-127)*/ 0x25, 0x7f, /* logical maximum (127)*/ 0x75, 0x08, /* report size (8)*/ 0x95, 0x02, /* report count (2)*/ 0x81, 0x06, /* input (data, variable, relative)*/ 0xc0, 0xc0
low pin count usb develop ment kit user?s guide DS41356B-page 18 ? 2009 microchip technology inc. 29. next, the device driver will be checked on the host pc. navigate to device manager on the host pc by selecting start>settings>control panel>system to open the system properties window. select the hardware tab and click the device manager button. 30. in the device manager window, expand the human interface devices. right click on each driver and select properties until the ?mouse enumeration demo? driver is located. see figure 2-4. example 2-6: device manager window and hid drivers installed the user is encouraged to familiarize themselves with the hid usage tables and hid descriptor tool. changing various aspects of the descriptors and then repeating the enumeration lab steps will help build on these concepts. 2.5 project lab 2 (hid mouse) 2.5.1 purpose this lab implements the low pin count usb demo board in a hid mouse application that moves the mouse pointer on the host pc in a circle. c:\microchip solutions\usb device - hid - mouse\hid - mouse ? firmware the user is encouraged to use these files as a reference when needed. note: the source code developed here is an exact replica of the usb device - hid ? mouse application found in the framework.
? 2009 microchip technology inc. DS41356B-page 19 2.5.2 overview of the hid mouse firmware as with most of the framework applications, the user defined source code is called from the processio() function in the .c file. the user defined firm- ware will manipulate the host pc mouse pointer to move in a single direction for 14 times through the main loop. after 14 times, the mouse pointer changes direction ulti- mately moving in a complete circle. a bit flag is initialized named emulate_mode that will toggle high/low whenever the push button on the low pin count usb develop- ment board is pressed. the status of this flag will start or stop pointer movement on the screen by not calling the user defined function, emulate_mouse() , which handles the mouse movement routines. the flowchart for the user defined function is shown in figure 2-4. figure 2-4: flowchart for the emulate_mouse() in the flowchart of figure 2-4, it can be seen that if the emulate_mode flag is ? 0 ?, the directional data transmitted along the usb is cleared. note that data is transmitted from the pic18f14k50 whether or not the flag is set. data is transmitted only when the sie is capable of transmitting it. this check is implemented in code by using the if(hidtxhandlebusy(lasttransmission) == 0) conditional statement. the lasttransmission is loaded at the time of transmission and processed by the hidtxhandlebusy macro in the conditional ? if ? statement. if the emulate_mode flag is set, the function enters into the mouse pointer movement algorithm. this is accomplished by keeping track of a counter variable, movement_length . when this variable exceeds 14, a buffer array is loaded with new directional data as supplied by the dir_table array defined at the top of the mouse.c file. each element of the array is accessed by incrementing the vector variable counter. the buffer array is then loaded into a hid_report_in[] buffer array that is used by the hidtxpacket macro to transmit the data along the usb to the host pc. emulate_mouse () emulate_mode = true yes yes movement_length > 14? change directional data to next vector clear directional data keep directional data as before no no no pic18f14k50 own the sie yes transmit directional data along usb return return true = 1 false = 0
low pin count usb develop ment kit user?s guide DS41356B-page 20 ? 2009 microchip technology inc. 2.5.3 procedure this lab expands on the descriptor code developed in lab 1. 1. create a new project ?project lab 2?, and build the framework as per procedure steps 1-15 in the previous lab, only this time use the source files found in c:\lpcusbdk_labs\lab2_files 2. ensure that the project build options are configured as was done in lab 1 steps 11 through 15. 3. in the project window open the mouse.c source file. 4. scroll down to find the variable definitions and uncomment the variables and arrays that will be used by the user defined function under the section of the source file: /**variables*****************************/ a) byte old_sw2,old_sw3; b) bool emulate_mode; c) byte movement_length; d) byte vector = 0; e) char buffer[3]; f) usb_handle lasttransmission; g) rom signed char dir_table[]={-4,-4,-4, 0, 4, 4, 4, 0}; 5. scroll down to the private prototype section and uncomment the user function prototype void emulate_mouse(void); 6. scroll down to the userinit() . it is here that all components pertinent to the application at hand are initialized. note the variables and function calls that are initialized. locate the // emulate_mode = true ; and uncomment the flag initialization. 7. scroll down to the processio() function. note the push button check that toggles the emulate_mode flag. uncomment the code: //emulate_mode = !emulate_mode; 8. finally, scroll down to the emulate_mouse function and insert the code in example 2-7 between the curly brackets in the section marked: //add emulate mouse code here
? 2009 microchip technology inc. DS41356B-page 21 example 2-7: user defi ned functional code for emulate_mouse() note that the hid mouse transmits in 3-byte packets. the format of this packet is as follows: ? this byte is typically used to identify mouse buttons. since this application does not require any mouse clicks, this byte is always zero. ? the second and third bytes represent horizontal (x) and vertical (y) displacements. compile the project. there should be no errors. testing the application 9. ensure that the low pin count usb development board is configured as in lab 1. 10. connect the pickit 2 programmer and open the pickit 2 programming software. 11. navigate to the .hex file located in the c:\lpcusbdk_labs\lab2_files for this lab and download to the pic18f14k50. if (emulate_mode == true) { //go 14 times in the same direction before changing if (movement_length > 14) { buffer[0] = 0; buffer[1] = dir_table[vector & 0x07]; //x-vector buffer[2] = dir_table [(vector+2) & 0x07]; //y-vector // go to the next direction in the table vector++; //reset the counter for when to change again movement_length = 0; }//end if (movement_length > 14) } else { //don't move the mouse buffer[0] = buffer[1] = buffer[2] = 0; } if(hidtxhandlebusy(lasttransmission) == 0) { //copy over the data to the hid buffer hid_report_in[0] = buffer[0]; hid_report_in[1] = buffer[1]; hid_report_in[2] = buffer[2]; //send the 3 byte packet over usb to the host. lasttransmission = hidtxpacket(hid_ep, (byte*)hid_report_in, 0x03); //increment the counter to change the data sent movement_length++; } note: the device created in the device manager from the previous lab will need to be removed so that the new device, created in this lab, can enumerate properly. in the device manager window, right-click on the device and select uninstall.
low pin count usb develop ment kit user?s guide DS41356B-page 22 ? 2009 microchip technology inc. 12. disconnect the pickit 2 and connect the low pin count usb demo board to the host pc port. 13. the device should enumerate and the leds on the board flash in accordance with the blinkusbstatus() discussed in the self-directed course. 14. pressing the push button should start and subsequently stop the mouse pointer moving in a circle on the host pc screen. the user is encouraged to experiment with this application by altering the length of time that the mouse pointer moves until a directional change or altering the values in the rom signed char dir_table[]={-4,-4,-4, 0, 4, 4, 4, 0} ; 2.6 project lab 3 (hid keyboard) caution in this lab, the pic18f14k50 is implemented as a hid keyboard device. the adc peripheral is configured to perform conversions on the voltage level present on the port pin connected to the potentiometer on the low pin count usb development board. the value in the adc result register is then used to create a numeric value between 4 and 29 that will display an alphabetic character between ?a? and ?z? on the host pc screen (refer to hid usage tables document section 10 ?keyboard/keypad page? ( 0x07 )). as the potentiometer is rotated, the character outputted to the screen will change accordingly. the user should note that this application could be applied to a data logger application with the potentiometer on the low pin count usb development board simulating a mixed signal interface to monitor an off-chip application. the data generated and transmitted via the usb could be connected and interpreted by a graphical user interface on the host pc to monitor real-time application behavior or used to store essential data for later analysis. 2.6.1 overview of the hid keyboard firmware the keyboard() is the user-defined function that is called from processio() to parse the data received from the adc module, transmit the numeric value along the usb and display the appropriate character on the screen. this function is implemented as a state machine. the state diagram for this function is shown in figure 2-5. caution a word of caution, this hid device has the potential to be harmful if a key combination is used that initiates a windows ? shortcut. great care should be taken to ensure that the transmitting buffer contains only keycodes that the user is confident will not produce any harmful key combinations.
? 2009 microchip technology inc. DS41356B-page 23 figure 2-5: state di agram for keyboard() referring to the state diagram, the individual states perform these general tasks: 1. state 0: this is a delay state used to ensure that the hold capacitor on the adc peripheral has sufficient time to charge before a conversion is initiated. 2. state 1: this state begins the conversion process by setting the go_done bit in the adcon0 control register. 3. state 2: checks for a completed conversion (go_done = 0 ) before allowing the state machine to move to the next state. 4. state 3: this final state reads the adc result register, converts the result to a value between 4 (?a?) and 29 (?z?), loads a hid buffer and transmits the resulting data along the usb to the host pc for output to an opened .txt document. the main point the user should take away from this lab is this: since the usb frame- work is a multitasking environment, no bl ocking code should be used. therefore, as shown in this lab, state machines will become the norm in many applications. the keyboard() state machine is called each time through the main loop. if the condition that changes the current state to the next state is not met, the state machine simply returns from the function without changing states. the next time through the main loop, the condition is once again checked. if the state condition has been met, the state is changed to the next sequential state. the state variable is declared as a type static as this will allow the current value in the state variable to remain after a return from the keyboard() . state 0 state 1 state 2 state 3 delaycounter < 9000 delaycounter > 9000 start adc conversion (set the go_done bit while go_done = 1 (adc conversion in progress) go_done = 0 (cleared in hardware) ? read adc result register ? load hid buffer ? transmit hid buffer contents along usb
low pin count usb develop ment kit user?s guide DS41356B-page 24 ? 2009 microchip technology inc. 2.6.2 procedure this application will require a few changes to the usb_descriptor.c file to configure the pic18f14k50 as a hid keyboard. note: the changes made to the report descriptor were done using the hid descriptor tool downloaded from http://www.usb.org/devel- opers/hidpage/ . the user is encouraged to spend some time reviewing the contents of this page and the resources available for developing hid applications. 1. create a new project ?project lab 3? as was done in the previous labs. the source files for lab 3 can be found in: c:\lpcusbdk_labs\lab3_files 2. ensure that the project build options are configured as was done in lab 1 steps 11 through 15. 3. open the usb_descriptor.c file and scroll down to the interface descriptor. uncomment the protocol code definition //hid_protocol_keyboard, 4. scroll down to the hid class specific descriptor and uncomment the size of the hid report macro //desc_config_word(63), the report descriptor has changed from the previous lab and will contain 63 components that the host pc will need to identify this device?s keyboard attributes. 5. scroll down to the report descriptor and add the code in example 2-8 in the section labeled: //add report descriptor here
? 2009 microchip technology inc. DS41356B-page 25 example 2-8: report de scriptor for keyboard() next, the keyboard.c source file will be configured. 6. in the project window, open the keyboard.c source file and scroll down to the userinit(). uncomment the port and adc initialization code. the user is urged to review the pic18f14k50 data sheet as to the significance of these initializations for the appropriate peripheral. // adcon0=0x29; // adcon1 = 0x00; // adcon2=0x3f; scroll down to the keyboard() and copy and paste the code in example 2-9 between the curly braces in the switch at: //add state machine code here 0x05, 0x01, // usage_page (generic desktop) 0x09, 0x06, // usage (keyboard) 0xa1, 0x01, // collection (application) 0x05, 0x07, // usage_page (keyboard) 0x19, 0xe0, // usage_minimum (keyboard leftcontrol) 0x29, 0xe7, // usage_maximum (keyboard right gui) 0x15, 0x00, // logical_minimum (0) 0x25, 0x01, // logical_maximum (1) 0x75, 0x01, // report_size (1) 0x95, 0x08, // report_count (8) 0x81, 0x02, // input (data,var,abs) 0x95, 0x01, // report_count (1) 0x75, 0x08, // report_size (8) 0x81, 0x03, // input (cnst,var,abs) 0x95, 0x05, // report_count (5) 0x75, 0x01, // report_size (1) 0x05, 0x08, // usage_page (leds) 0x19, 0x01, // usage_minimum (num lock) 0x29, 0x05, // usage_maximum (kana) 0x91, 0x02, // output (data,var,abs) 0x95, 0x01, // report_count (1) 0x75, 0x03, // report_size (3) 0x91, 0x03, // output (cnst,var,abs) 0x95, 0x06, // report_count (6) 0x75, 0x08, // report_size (8) 0x15, 0x00, // logical_minimum (0) 0x25, 0x65, // logical_maximum (101) 0x05, 0x07, // usage_page (keyboard) 0x19, 0x00, // usage_minimum (reserved (no event indicated)) 0x29, 0x65, // usage_maximum (keyboard application) 0x81, 0x00, // input (data,ary,abs) 0xc0
low pin count usb develop ment kit user?s guide DS41356B-page 26 ? 2009 microchip technology inc. example 2-9: keyboard () state machine code //delay to allow the hold capacitor on the adc to charge case 0: if(++delaycounter>9000) { delaycounter = 0; state = 1; } break; case 1: adcon0bits.go_done = 1; //start an adc conversion state = 2; break; case 2: if(adcon0bits.go_done == 0) //check if conversion is //completed { state = 3; } break; case 3: hidoutput = adresh>>3;//shift the result in adresh //left by three if(hidoutput<=4) hidoutput = 4; if(hidoutput>=29) hidoutput = 29; //can the sie transmit? if((hidtxhandlebusy(lasttransmission) == 0)) { //load the hid buffer hid_report_in[0] = 0; hid_report_in[1] = 0; hid_report_in[2] = hidoutput; hid_report_in[3] = 0; hid_report_in[4] = 0; hid_report_in[5] = 0; hid_report_in[6] = 0; hid_report_in[7] = 0; //send the 8 byte packet over usb to the host. lasttransmission = hidtxpacket(hid_ep, (byte*)hid_report_in, 0x08); state = 0; } break;
? 2009 microchip technology inc. DS41356B-page 27 note that the hid keyboard transmits in 8-byte packets along the usb. the format of this packet is as follows: ? the first byte is used for a modifier such as a shift or ctrl character. (i.e., a simultaneous shift and character press on the typical keyboard.) ? the second byte is reserved. ? the remaining bytes are used to carry numeric values that contain the desired keyboard characters pressed. compile the project. there should be no errors. testing the application 7. connect the pickit 2 programmer and open the pickit 2 programming software 8. navigate to the .hex file for this lab and download to the pic18f14k50. 9. disconnect the pickit 2. open a new notepad, word document or other text editor program and click inside the document to place the cursor. 10. connect the low pin count usb demo board to the host pc port. the device should enumerate as ?keyboard demo?. 11. within the selected text editor, a series of character entries should appear. 12. turn the potentiometer on the low pin count usb demo board to change the character on the screen. the user is encouraged to experiment with this application by referring to the keyboard usage page and changing the keyboard packet transmitted in the state machine.
low pin count usb develop ment kit user?s guide DS41356B-page 28 ? 2009 microchip technology inc. 2.7 project lab 4 (cdc ? serial emulator) in this lab, the pic18f14k50 is used as a serial emulator taking an rs-232 data trans- mission using the enhanced universal asynchronous synchronous receiver transmit- ter (eusart) peripheral and converting it to the usb protocol within firmware. many embedded applications continue to use the rs-232 interface to communicate with external systems. however, as usb becomes more prevalent, rs-232 ports are disap- pearing from newer pc?s. a simple solution is to emulate rs-232 over the usb. in this example, a virtual com port is created that will allow the usb connection to appear as an rs-232 com connection. furthermore, this example makes use of windows drivers that already exist eliminating the need to alter existing software such as the hyper terminal application. the rs-232 connector on the low pin count usb development board is configured so that the pic18f14k50 can be used as a data terminal equipment (dte) device to interface with data communications equipment (dce) devices such as alarm systems, modems etc. to accommodate this lab and eliminate the need for the user to create their own dce interface circuitry, a null-modem gender changer has been provided in the kit to crosslink the transmit and receive lines so that the low pin count usb devel- opment board can be converted from a dte device to a dce device. in this way, the main concepts of serial emulation can be delivered using only two hyperlink terminals on a single pc with one rs-232 serial com port and one usb connection. microchip?s full-speed usb firmware framework provides information files ( .inf ) for all of its cdc application examples that automate windows driver alterations freeing the user from doing this manually. once the pic18f14k50 has been programmed and then connected to the pc usb port, windows ?new hardware found wizard? will prompt the user for additional driver information. at this point, the user need only direct windows to the directory containing the appropriate .inf file. microchip?s full-speed usb firmware framework provides all the source code necessary to perform low-level rs-232 functions, thereby abstracting this from the user. notice kits shipped with the rs-232 pin corrector (p/n 04-02087r1) do not require the null modem gender changer but will instead require a female/female gender changer that does not cross- link the transmit and receive lines. the pin corrector is not used in this lab as the rs-232 con- nector on this version of the low pin count usb development board is configured as a dce device. applications using the low pin count usb development board as a dte device will require the use of the pin corrector. note: the only information that is required by the user in the .inf is the vendor identification (vid) and product identification (pid) numbers specific to their original design.
? 2009 microchip technology inc. DS41356B-page 29 2.7.1 overview of the cdc ? serial emulator firmware the cdc serial emulator firmware flow is shown in figure 2-6. figure 2-6: flowchart for cdc serial emulator code rs232 out buffer available and usb out buffer not empty yes yes copy usb out buffer to rs232 out buffer copy next byte to eusart copy usb in buffer to usb buffer add byte to rs232 in buffer rs232 out buffer not empty and eusart is empty eusart has a byte yes yes rs232 in buffer has data and usb in buffer available cdctxservice( ) processio( ) no no no no
low pin count usb develop ment kit user?s guide DS41356B-page 30 ? 2009 microchip technology inc. referring to the flowchart in figure 2-6, the firmware located in the processio() first checks if the previous rs-232 transmission has been sent via the usb using the rs232_out_data_rdy flag. if this flag is cleared (indicating previous transmission has been sent), firmware then checks if any new data has been sent from the rs-232 connection and is ready to be transmitted via the usb using the getsusbusart() . this function copies data into a buffer and returns the number of bytes the buffer con- tains. the function ensures that only the expected numbers of bytes, in this case 64, are actually copied into this buffer. also, if there is no data available, the function returns a zero value indicating no data is available. in this way the function does not wait for data and is therefore, non-blocking, keeping in mind that all firmware must conform to this multitasking environment. following the rs-232 data check, the firmware then checks if the eusart transmit register, txreg, is empty. this is accomplished using the mtxrdyusart() macro, which checks the trmt bit in the txsta (transmit status control) register in the eusart peripheral. if the trmt bit is cleared, the txreg is full, and empty if the trmt bit is set. note that this bit is automatically set following a successful transmis- sion from the txreg. if set, the data collected into the buffer by the getsusbusart() is then transferred into the txreg one byte at a time each time through the main loop. again, such macros take care of the low-level rs-232 communication in a non-blocking fashion so the user doesn?t have to. if the txreg isn?t empty, then the previous data has not been transmitted via the usb and should not be overwritten. the firmware next checks to see if the cdc class device is ready to transmit data. this is accomplished by using the musbusartistxrfready() flag. the user must ensure that this flag is set to ? 1 ? before calling the putusbusart() function. as a safety pre- caution, this function checks the state one more time to make sure it does not override any pending transactions. this function writes data to the usb. the cdctxsevice() services the transfer of data to the host. this function keeps track of a state machine and breaks up long strings of data into multiple usb data pack- ets. it is called once each time through the main program loop. the state machine for the cdctxservice() is shown in figure 2-7 and the source code can be found in the usb_function_cdc.c source file. the reader is encouraged to reference this firmware and compare it against the state diagram at their leisure.
? 2009 microchip technology inc. DS41356B-page 31 figure 2-7: cdctxservice( ) state diagram 2.7.2 procedure this application requires significant changes to the usb_descriptor.c file to configure the pic18f14k50 as a cdc device. note the absence of the report descriptor. the user is encouraged to spend some time reviewing the usb_descriptor.c file and com- pare it against the information found in the universal serial bus class definitions for communications devices document referenced at the beginning of this chapter. note that this lab applies the same firmware found in the cdc ? serial emulator application example in microchip?s full-speed usb firmware framework application examples and can be used as a reference for this lab. 1. create a new project for lab 4, using the project wizard, called ?project lab 4? as was done in the previous labs. the only files added, at this point, will be the usb_descriptor.c and main.c source files, as well as a new unique descrip- tor for lab 4 rm18f14k50.lkr can be found in: c:\lpcusbdk_labs\lab4_files step through to close the project wizard. this time, the project will be set up to resemble the application examples in the framework using sub-folders to distin- guish and organize the different source files in the project window. all remaining source/header files will be added from the project window. 2. right click on the source files folder in the project window and select create subfolder ... cdc_tx_ready cdc_tx_busy cdc_tx_completing cdc_tx_busy_zlp cdc_tx_lenl=0 cdc_tx_len==0 cdc_bulk_bd_in.cnt low pin count usb develop ment kit user?s guide DS41356B-page 32 ? 2009 microchip technology inc. figure 2-8: creating a sub-folder in the project window name the new folder ?usb stack? and click ok . 3. right click on this new usb stack folder and select add files . in the add files to project window, navigate to c:\microchip solutions\microchip\usb and select the usb_device.c source file. ensure that ?system: file(s) are external to project, use absolute path? is selected then click open . figure 2-9: adding the usb_device.c file to the usb stack folder this should add the usb_device.c to the ?usb stack? folder in the project window.
? 2009 microchip technology inc. DS41356B-page 33 repeat this step to add the usb_function_cdc.c file from the c:\microchip solutions\microchip\usb\cdc device driver directory to the same ?usb stack? folder. 4. in the project window create two new sub-folders under the header files folder called ?common? and ?usb stack? as per step 2 of this lab. 5. right click on the ?usb stack? folder and add the following files from the c:\microchip solutions\microchip\include\usb directory as was done in step 3 of this lab: ? usb.h ? usb_ch9.h ? usb_common.h ? usb_device.h ? usb_function_cdc.h ? usb_hal.h ? usb_hal_pic18.h 6. right click on the ?common? folder and add the following files from the c:\microchip solutions\microchip\include directory as was done in step 3 of this lab: ? compiler.h ? generictypedefs.h 7. ensure that the project build options are configured as was done in lab 1 steps 11 through 15. 8. compile the project. there should be no errors. the project window should now resemble figure 2-10.
low pin count usb develop ment kit user?s guide DS41356B-page 34 ? 2009 microchip technology inc. figure 2-10: project window for lab 4 9. next, the eusart peripheral will need to be initialized to enable asynchronous communication with a baud rate of 19200. to do this, open the main.c file and scroll down to the initializeusart(). this function is called by the userinit() . note that in this function, code has been formatted to allow configuration dependant on the specific device and compiler used. copy and paste the contents of example 2-10 into the section of the initialize- usart() function labeled: //add c18 pic18f14k50 eusart initialization code here
? 2009 microchip technology inc. DS41356B-page 35 example 2-10: initializeusart() code the reader is encouraged to review the data sheet for the pic18f14k50 eusart section for more information on the specifics of the configuration code. next, the application specific code will be added that will implement the flowchart shown in figure 2-6. 10. scroll down to the processio() and copy and paste the contents of example 2-11 into the section labeled: /***************************************************** add code to check if rs232 has been sent along usb and the code to check if any new rs232 transmission has been received and stored ******************************************************/ as per the flowchart in figure 2-6, this code will ensure that the buffer containing the data transmitted from the rs-232 has been sent to the usb firmware. if so, the code then checks for any new rs-232 data that has been stored in the buffer. #if defined(__18cxx) unsigned char c; #if defined(__18f14k50) anselhbits.ans11 = 0; // make rb5 digital so usart can //use pin for rx #endif uart_trisrx=1; // rx uart_tristx=0; // tx txsta = 0x24; // tx enable brgh=1 rcsta = 0x90; // single character rx spbrg = 0x70; spbrgh = 0x02; // 0x0271 for 48mhz -> 19200 baud baudcon = 0x08; // brg16 = 1 c = rcreg; // read #endif
low pin count usb develop ment kit user?s guide DS41356B-page 36 ? 2009 microchip technology inc. example 2-11: rs-232 buffer check 11. next, the code that will check and then load the eusart transmit shift register (txreg) with the contents of the rs-232 buffer will be entered. copy and paste the contents of example 2-12 into the section labeled: /******************************************************* add the code that will check if the eusart txreg is empty. if so, begin sending data from rs232 transmission into the txreg one byte at a time *******************************************************/ example 2-12: txreg check and load code 12. finally, the code to check if the cdc class device is ready to send data into the usb transmit buffer will be entered. copy and paste the contents of code in example 2-13 into the section labeled: /********************************************************** add the code that will check if the cdc class device is ready to load the usb buffer *********************************************************/ // only check for new usb buffer if the old rs232 buffer is // empty. // additional usb packets will be nak'd // until the buffer is free. if (rs232_out_data_rdy == 0) { lastrs232out = getsusbusart(rs232_out_data,64); if(lastrs232out > 0) { rs232_out_data_rdy = 1; // signal //buffer full rs232cp = 0;// reset the current position } } if(rs232_out_data_rdy && mtxrdyusart()) { putcusart(rs232_out_data[rs232cp]); ++rs232cp; if (rs232cp == lastrs232out) rs232_out_data_rdy = 0; }
? 2009 microchip technology inc. DS41356B-page 37 example 2-13: check cdc class device code 13. at this point, all the necessary code to run the cdc ? serial emulator application is complete. compile the project. there should be no errors. installing application drivers 14. connect the pickit 2 programmer and open the pickit 2 programming software. 15. navigate to the .hex file for this lab and download to the pic18f14k50. 16. disconnect the pickit 2. 17. connect the low pin count usb demo board to the host pc port. windows should recognize the pic18f14k50 as ?cdc rs-232 emulation demo?. windows will now prompt the user for driver information. 18. in the ?welcome to the found new hardware wizard? window, select ?no, not this time? and then next (see figure 2-11). figure 2-11: found new hardware wizard window if((musbusartistxtrfready()) && (nextusbout > 0)) { putusbusart(&usb_out_buffer[0], nextusbout); nextusbout = 0; }
low pin count usb develop ment kit user?s guide DS41356B-page 38 ? 2009 microchip technology inc. 19. the wizard will then prompt the user for a location from which to load the software for the communication port. select ?install from a list or specific location (advanced)? and click next (see figure 2-12). figure 2-12: selecting software location for communications port the wizard now prompts the user for the location of the .inf file that windows will use to automatically configure the binary driver files ( .sys files) to create the virtual com port connection for the usb. ensure that both ?search for the best driver in these loca- tions? and ?include this location in the search? are both selected. select browse and navigate to the lab 4 source files in the c:\lpcusbdk_labs\lab4_files\inf\win2k_winxp directory (see figure 2-13). highlight the win2k_winxp file and click ok .
? 2009 microchip technology inc. DS41356B-page 39 figure 2-13: directing windows to the .inf file for the cdc ? serial emulator application click next . the window should now begin loading the software. if any warnings are issued, select continue anyway. 20. the wizard should indicate that the software for the communications port was successfully installed. select finish. (see figure 2-14.) figure 2-14: successful software installation window
low pin count usb develop ment kit user?s guide DS41356B-page 40 ? 2009 microchip technology inc. next, the virtual com port will be checked in the device manager to identify the com port number. establish communication 21. using step 29 in project lab 1 to navigate to the device manager, expand the ports (com and lpt). the new virtual com port (usually com 5 and above on most pcs) created by the .inf file should be found in the ports (com & lpt) drop-down list in the device manager window. if there is difficulty locating the vir- tual com port, right click on each driver and select properties until the cdc rs-232 emulation demo is located. note the com port number for both the vir- tual com port and the com port used for an rs-232 connection (serial port connection on the host pc). figure 2-15 shows a list of com ports available. the reader?s list may differ. figure 2-15: example list of av ailable com ports in the device manager this com port number will be used in the hyper terminal program to establish connec- tivity to both the usb and rs-232 connections between the low pin count usb development board and host pc. 22. open a hyper terminal window by selecting within windows, start>programs>accessories>communications>hyperterminal . the hyper terminal program should now prompt the user for a ?connection description?. 23. name this first connection ?usb connection? and click ok . (see figure 2-16.)
? 2009 microchip technology inc. DS41356B-page 41 figure 2-16: hyper terminal connection description 24. in the ?connect to? window, select the virtual com port that was noted in step 21 in the ?connect using? drop-down menu and select ok . in figure 2-17, the virtual com port is on com7. note that this may differ on the user?s pc. figure 2-17: hyper termi nal connect to window 25. in the com properties window, configure the connection as shown in figure 2-18 with a baud rate of 19200 and click apply then ok .
low pin count usb develop ment kit user?s guide DS41356B-page 42 ? 2009 microchip technology inc. figure 2-18: hyper termi nal com properties window this now establishes a connection between the low pin count usb development board usb connector and the host pc com port. 26. next, connect the rs-232 serial cable to the connector on the low pin count usb development board and to a serial port connector on the host pc using a ?gender changer? adapter. 27. repeat steps 22 to 25 to establish an rs-232 connection using the related port noted in step 21 for the serial port connector on the host pc. name this con- nection ?rs232 connection? and ensure that the com properties resemble figure 2-18. testing the application 28. once connected, click inside the rs232 connection com window and type a message. note that unless configured to echo locally, the originating message com window will not print the message. the message should be printed in the ?usb connection? com window as shown in figure 2-19.
? 2009 microchip technology inc. DS41356B-page 43 figure 2-19: confir ming rs-232 to usb communication this will confirm communication from the host pc via an rs-232 connection into the pic18f14k50, which in turn transmits data received back to the host pc. in other words, an rs-232 to usb conversion.
low pin count usb develop ment kit user?s guide DS41356B-page 44 ? 2009 microchip technology inc. notes:
low pin count usb development kit user?s guide ? 2009 microchip technology inc. DS41356B-page 45 appendix a. schematics a.1 introduction this appendix contains the low pin count usb development kit hardware diagrams. figure a-1: low pin count usb development board bill of materals qty description 1 ic, pic18f14k50, 20p dip 1 ic smt, max3232cpwr ,drvr/rcvr mltch rs232 16tsso (u3) 5 cap smt, 0.1uf 0603 cer 16v 10% x7r (c6 - c10) 2 cap smt, 0.1uf 0805 cer 50v 10% x7r (c1, c3) 1 cap smt, 0.47uf 0805 cer 16v 10% x7r (c2) 2 cap smt, 22pf 0805 cer 100v 5% c0g (c4, c5) 4 res smt, 330-ohm 1/16w 1% 0603 (r8 - r11) 2 res smt, 1.0k-ohm 1/10w 1% 0805 (r1, r3) 1 res smt, 10k-ohm 1/10w 1% 0805 (r2) 1 res smt, 150k-ohm 1/10w 1% 0805 (r12) 4 res smt, 470-ohm 1/10w 1% 0805 (r4 - r7) 1 res pot, 10k-ohm 1/2w thumbwh cerm st (pot 1) 4 led, 565nm green clear 0805 t/r (d1 - d4) 1 osc smt, 12.000mhz crystal 18pf fund smd (hc49) (y1) 1 switch smt, push button spst mom 6mm 160gf/230gf (s1) 1 conn smt, recpt, usb mini-b 5pos ra (j1) 1 conn, d-sub, 9p plug rt angle w/ jack screws (j15) 1 conn, recpt, 1x14 pin 0.100" str (j11) 2 conn, hdr, 1x6 breakaway, 0.100" pitch, 0.025 sq, ra, (0.230/0.090) (j6, j13) 1 conn, hdr, 1x2, 0.100" pitch, 0.025 sq post, tin (0.135"/0.380"), pol (j9) 1 conn, hdr, 1x3 breakaway, 0.100" pitch, 0.025 sq post, gd (0.100"/0.230") (j14) 1 socket, 20p dip 0.300w collet open frame (@xu1) 1 -spare- location (u2, j2 - j5, j7, j8)
low pin count usb develop ment kit user?s guide DS41356B-page 46 ? 2009 microchip technology inc. a.2 schematics figure a-2: pickit? 2 usb development schematic max323cpwr v pp v dd gnd icspdat icspclk t1g j6 pickit? serial j13 330 330 330 330 sw?b3s1002 s1 r1 1k 10k r2 j3 +v j2 1k cw pot1 10k ccw r3 c3 0.1uf pcb trace on solder side jumper not populated c2 0.47uf j12 pic18f1xk50-i/ss pic18f1xx50-i/p u2 u1 +v c8 c9 0.1uf 0.1uf r8 r9 r11 r10 u3 +v c6 c7 0.1uf 0.1uf c10 0.1uf j15 de9p-mrs icsp1 j14 +v j9 v in 3phdr 0.1uf c1 y1 12 mhz 22pf c5 c4 22pf pickit? 1 hdr1x14 j11 pcb trace on solder side jumper not populated j4 j5 j7 j8 d1 d2 d3 d4 +v r12 150k 470 470 470 470 r4 r5 r6 r7 j1 1 2 3 4 5 6 1 2 3 4 5 6 1 2 3 4 5 6 7 8 9 16 2 14 7 13 8 6 1 3 4 5 11 10 12 9 15 pin1 pin2 pin3 pin4 1 3 4 6 7 2 5 8 9 10 11 12 13 14 1 2 3 4 5 6 2 3 20 19 18 17 16 15 14 13 12 11 1 2 3 4 5 6 7 8 9 10 2 1 3 1 2 v bus d- d+ shield v dd ra5/osc1/ckli ra4/an3/osc2/clko ra3/mclr/v pp rc5/cpp1/p1a/t0cki rc4/p1b/c12out/srq rc3/an7/p1c/c12in3-/pgm rc6/an8/ss/t13cki/t1osci rc7/an9/sdo/t1osco rb7/tx/ck v ss ra0/d+/pgd ra1/d-/pgc v usb rc0/an4/c12in+/int0/v ref + rc1/an5/c12in1-/int1/v ref - rc2/an6/p1d/c12in2-/cv ref /int2 rb4/an10/sdi/sda rb5/an11/rx/dt rb6/sck/scl v cc v+ t1out t2out r1in r2in v- c1+ c1- c2+ c2- t1in t2in r1out r2out gnd v in v bus v in ra5 ra4 ra3 rc5 rc4 rc3 rc6 rc7 rb7/cs/tx d+/icspdat d-/icspclk rc0 rc1 rc2 rb4/sda/sdi/rts rb5/sdo/rx rb6/scl/sck/cts rb4/ads/sdi/rts 1 ra3 rb7/cs/tx rb4/sda/sdi/rts rb6/scl/sck/cts rb5/sdo/rx rb4/sda/sdi/rts rb7/cs/tx rb5/sdo/rx rb6/scl/sck/cts pin5 pin6 pin7 pin8 pin9 ra3 +v d+/icspdat d-/icspclk v bus d+/icspdat d-/icspclk rc3 rc2 rc1 rc0 ra5 ra4 ra3 rc5 rc4 rc3 rc0 rc1 rc2 +v gnd d+/icspdat d-/icspclk
? 2009 microchip technology inc. DS41356B-page 47 figure a-3: pickit? 2 debug header u1 v dd ra5/osc1/clki ra4/an3/osc2/clko icddata icdclk rc5/ccp1/p1a/t0cki rc4/p1b/c12out/srq nc nc rc3/an7/p1c/c12in3-/pgm rc7/an9/sdo/t1osco14 rb7/tx/ck v ss pgd/d+/ra0 pgc/d-/ra1 vusb nc v ref +/int0/c12in+/an4/rc0 v ref -/int1/c12in1-/an5/rc1 nc int2/cv ref /c12in2-/p1d/an6/rc2 nc sda/sdi/an10/rb4 dt/rx/an11/rb5 scl/sck/rb6 pic18f1xk50-icd_s028 v dd 0.1 u f c1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 osc1 osc2 icddata icdclk ra3 rc5 rc4 rc3 rc6 rc7 rb7 28 27 26 25 24 23 22 21 20 19 18 17 16 15 d+ vusb d- rc0 rc1 rc2 rb4 rb5 rb6 ra3/mclr/v pp rc6/an8/ss/t13cki icdmclr/v pp icdmclr/v pp u2 pic18f1xk50-i/p v dd v dd ra5/osc1/clki ra4/an3/osc2/clko rc5/cpp1/p1a/t0cki rc4/p1b/c12out/srq rc3/an7/p1c/c12in3-/pgm rc7/an9/sdo/t1osco rb7/tx/ck v ss ra0/d+/pgd ra1/d-/pgc vusb rc0/an4/c12in+/int0/v ref + rc1/an5/c12in1-/int1/v ref - rc2/an6/p1d/c12in2-/cv ref /int2 rb4/an10/sdi/sda rb5/an11/rx/dt rb6/sck/scl 1 2 3 4 5 6 7 8 9 10 20 19 18 17 16 15 14 13 12 11 osc1 osc2 ra3 rc5 rc4 rc3 rc6 rc7 rb7 d+ d- vusb rc0 rc1 rc2 rb4 rb5 rb6 ra3/mclr/v pp rc6/an8/ss/t13cki/t1osci v dd icddata icdclk v pp v dd gnd icspdat icspclk t1g j1 1 2 3 4 5 6 icdmclr/v pp
low pin count usb develop ment kit user?s guide DS41356B-page 48 ? 2009 microchip technology inc. notes:
? 2009 microchip technology inc. DS41356B-page 49 low pin count usb development kit user?s guide notes:
DS41356B-page 50 ? 2009 microchip technology inc. americas corporate office 2355 west chandler blvd. chandler, az 85224-6199 tel: 480-792-7200 fax: 480-792-7277 technical support: http://support.microchip.com web address: www.microchip.com atlanta duluth, ga tel: 678-957-9614 fax: 678-957-1455 boston westborough, ma tel: 774-760-0087 fax: 774-760-0088 chicago itasca, il tel: 630-285-0071 fax: 630-285-0075 dallas addison, tx tel: 972-818-7423 fax: 972-818-2924 detroit farmington hills, mi tel: 248-538-2250 fax: 248-538-2260 kokomo kokomo, in tel: 765-864-8360 fax: 765-864-8387 los angeles mission viejo, ca tel: 949-462-9523 fax: 949-462-9608 santa clara santa clara, ca tel: 408-961-6444 fax: 408-961-6445 toronto mississauga, ontario, canada tel: 905-673-0699 fax: 905-673-6509 asia/pacific asia pacific office suites 3707-14, 37th floor tower 6, the gateway harbour city, kowloon hong kong tel: 852-2401-1200 fax: 852-2401-3431 australia - sydney tel: 61-2-9868-6733 fax: 61-2-9868-6755 china - beijing tel: 86-10-8528-2100 fax: 86-10-8528-2104 china - chengdu tel: 86-28-8665-5511 fax: 86-28-8665-7889 china - hong kong sar tel: 852-2401-1200 fax: 852-2401-3431 china - nanjing tel: 86-25-8473-2460 fax: 86-25-8473-2470 china - qingdao tel: 86-532-8502-7355 fax: 86-532-8502-7205 china - shanghai tel: 86-21-5407-5533 fax: 86-21-5407-5066 china - shenyang tel: 86-24-2334-2829 fax: 86-24-2334-2393 china - shenzhen tel: 86-755-8203-2660 fax: 86-755-8203-1760 china - wuhan tel: 86-27-5980-5300 fax: 86-27-5980-5118 china - xiamen tel: 86-592-2388138 fax: 86-592-2388130 china - xian tel: 86-29-8833-7252 fax: 86-29-8833-7256 china - zhuhai tel: 86-756-3210040 fax: 86-756-3210049 asia/pacific india - bangalore tel: 91-80-3090-4444 fax: 91-80-3090-4080 india - new delhi tel: 91-11-4160-8631 fax: 91-11-4160-8632 india - pune tel: 91-20-2566-1512 fax: 91-20-2566-1513 japan - yokohama tel: 81-45-471- 6166 fax: 81-45-471-6122 korea - daegu tel: 82-53-744-4301 fax: 82-53-744-4302 korea - seoul tel: 82-2-554-7200 fax: 82-2-558-5932 or 82-2-558-5934 malaysia - kuala lumpur tel: 60-3-6201-9857 fax: 60-3-6201-9859 malaysia - penang tel: 60-4-227-8870 fax: 60-4-227-4068 philippines - manila tel: 63-2-634-9065 fax: 63-2-634-9069 singapore tel: 65-6334-8870 fax: 65-6334-8850 taiwan - hsin chu tel: 886-3-572-9526 fax: 886-3-572-6459 taiwan - kaohsiung tel: 886-7-536-4818 fax: 886-7-536-4803 taiwan - taipei tel: 886-2-2500-6610 fax: 886-2-2508-0102 thailand - bangkok tel: 66-2-694-1351 fax: 66-2-694-1350 europe austria - wels tel: 43-7242-2244-39 fax: 43-7242-2244-393 denmark - copenhagen tel: 45-4450-2828 fax: 45-4485-2829 france - paris tel: 33-1-69-53-63-20 fax: 33-1-69-30-90-79 germany - munich tel: 49-89-627-144-0 fax: 49-89-627-144-44 italy - milan tel: 39-0331-742611 fax: 39-0331-466781 netherlands - drunen tel: 31-416-690399 fax: 31-416-690340 spain - madrid tel: 34-91-708-08-90 fax: 34-91-708-08-91 uk - wokingham tel: 44-118-921-5869 fax: 44-118-921-5820 w orldwide s ales and s ervice 01/16/09


▲Up To Search▲   

 
Price & Availability of DS41356B

All Rights Reserved © IC-ON-LINE 2003 - 2022  

[Add Bookmark] [Contact Us] [Link exchange] [Privacy policy]
Mirror Sites :  [www.datasheet.hk]   [www.maxim4u.com]  [www.ic-on-line.cn] [www.ic-on-line.com] [www.ic-on-line.net] [www.alldatasheet.com.cn] [www.gdcy.com]  [www.gdcy.net]


 . . . . .
  We use cookies to deliver the best possible web experience and assist with our advertising efforts. By continuing to use this site, you consent to the use of cookies. For more information on cookies, please take a look at our Privacy Policy. X